function debounce(fn, delay) {
  let timeout = null
  let context = this
  return function (...args) {
    if (timeout != null) {
      clearTimeout(timeout)
    }
    timeout = setTimeout(() => {
      fn.apply(context, args)
    }, delay)
  }
}